package com.bringway.p2p.controller;


import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.ZctztjService;

import net.sf.json.JSONObject;

/**
 * @author js
 * @version 创建时间：2016年6月29日 
 * @功能: 每日注册投资信息统计界面
 */

@Controller
@RequestMapping("/zctztj")
public class ZctztjController extends JsonController{
	Logger logger = Logger.getLogger(ZctztjController.class);
	@Autowired
	private ZctztjService zctztjService;
	/**
	 * 
	 * @param request 每日注册投资数量统计查询
	 * @param response 查询功能
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryZctztjList")
	public ModelAndView queryZctztjList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		
		List list = zctztjService.queryZctztjList(params);
		int count = zctztjService.getZctztjCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
	/**
	 * @方法名称:queryTzxxList
	 * @方法描述:每日统计查询投资信息
	 * @author js
	 * @date 2016年6月29日上午11:20:26
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryTzxxList")
	public ModelAndView queryTzxxList(HttpServletRequest request ,HttpServletResponse response)throws Exception{
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		String tzsj = RequestUtils.getStringParameter(request, "tzsj");
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		JSONObject params = new JSONObject();
		params.put("tzsj", tzsj);
		params.put("start", start);
		params.put("limit", limit);
		List list = zctztjService.queryGrtz(params);
		int total = zctztjService.getGrtzCount(params);
		float sumJe = zctztjService.getGrtzJe(params);
		
		DecimalFormat df = new DecimalFormat("#.00");
		JSONObject result = new JSONObject();
		result.put("data", list);
		result.put("total", total);
		result.put("sumJe", df.format(sumJe));
		if (null!=page) {//新版本,传参
			int totalPage=total%limit==0?total/limit:total/limit+1;
			result.put("totalPage", totalPage);
			//合计行 数据 开始
			Map<String, Object> map=new HashMap<>();
			map.put("USERID", "合计:");//key是字段名
			map.put("TZSJ", sumJe);//key是字段名
			result.put("userdata", map);
			//合计行 数据 结束
		}
			serialize(request, response, result);
		return null;
	}
	

}
